<?php namespace App\Modules\Index\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use App\Modules\Common\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;

/**
 * Base index section controller
 *
 * @package App\Http\Controllers\Admin
 */
class IndexController extends Controller {

    /**
     * Admin index page
     *
     * @return \Illuminate\View\View
     */
    public function getIndex() {
        return $this->render('index');
    }

    /**
     * Make a view render
     *
     * @param null $view
     * @param array $data
     * @param array $mergeData
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    protected function render($view = null, $data = [], $mergeData = []){
        return view('index::' . $view, $data, $mergeData);
    }

    /**
     * Change locale
     *
     * @param string $locale
     * @return \Illuminate\Http\RedirectResponse
     */
    public function getChangeLocale($locale) {
        Session::put('locale', $locale);

        return redirect()->back();
    }

    /**
     * Missing method handler
     *
     * @param array $parameters
     * @return \Illuminate\View\View
     */
    public function missingMethod($parameters = array())
    {
        return view('errors.404', ['admin' => 'index::']);
    }
}
